package com.rs.entity;

import java.io.Serializable;

public class Response<T> implements Serializable {

    public Response() {
    }

    /** 返回数据 */
    protected T data;
    protected Integer code;
    protected long count;

    protected String msg;

    public static <E> Response<E> success() {
        return success(null);
    }

    public static <E> Response<E> success(E data) {
        final Response<E> resp = new Response<>();
        resp.data = data;
        resp.code = 0;
        resp.msg = "返回成功";
        resp.count = 0;
        return resp;
    }

    public static  Response<String> fail(String message) {
        final Response<String> resp = new Response<>();
        resp.code = 500;
        resp.msg = message;
        return resp;
    }

    public static <E> Response<E> list(E data,long count) {
        final Response<E> resp = new Response<>();
        resp.data = data;
        resp.code = 0;
        resp.msg = "返回成功";
        resp.count = count;
        return resp;
    }


    public T getData() {
        return data;
    }

    public Response<T> setData(T data) {
        this.data = data;
        return this;
    }

    public Integer getCode() {
        return code;
    }

    public Response<T> setCode(Integer code) {
        this.code = code;
        return this;
    }

    public String getMsg() {
        return msg;
    }

    public Response<T> setMsg(String msg) {
        this.msg = msg;
        return this;
    }


    public long getCount() {
        return count;
    }

    public Response<T> setCount(Integer count) {
        this.count = count;
        return this;

    }

    @Override
    public String toString() {
        return "Response{" +
                "data=" + data +
                ", code=" + code +
                ", count=" + count +
                ", msg='" + msg + "\'" +
                "}";
    }
}
